package org.liveboardgames.agricola.business;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.liveboardgames.agricola.access.IPlayerDao;
import org.liveboardgames.agricola.domain.common.Peep;
import org.liveboardgames.agricola.domain.player.Player;
import org.liveboardgames.agricola.model.enums.BirthStatusEnum;

public class PlayerServiceImpl implements IPlayerService {

  private IPlayerDao playerDao;

  private IFarmService farmService;

  /**
   * @param farmService
   *          the {@link #farmService} to set
   */
  public void setFarmService(IFarmService farmService) {
    this.farmService = farmService;
  }

  /**
   * @param playerDao
   *          the {@link #playerDao} to set
   */
  public void setPlayerDao(IPlayerDao playerDao) {
    this.playerDao = playerDao;
  }

  public List<Player> initializePlayers(List<Player> players) {
    for (Player player : players) {
      Set<Peep> peeps = new HashSet<Peep>();
      for (int i = 0; i < 2; i++) {
        Peep peep = new Peep();
        peep.setStatus(BirthStatusEnum.ADULT);
        peeps.add(peep);
      }
      player.setPeeps(peeps);

      farmService.initializeFarm(player);
    }

    return players;
  }

}
